/*
 * Copyright 2019 bingoogolapple
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package cn.bingoogolapple.transformerstip;

import ohos.agp.components.Component;
import ohos.agp.components.Text;
import ohos.agp.utils.Color;

/**
 * 用于只有文字的浮窗，不写布局文件，在 Java 代码中设置文本内容属性
 *
 * @author 王浩 邮件:bingoogolapple@gmail.com
 * @since 2021-04-25
 */
public class SimpleTextTip extends TransformersTip {
    private Text mContentTv;

    /**
     * 初始化对象
     *
     * @param anchorView 锚点控件
     * @param contentView 显示控件
     */
    public SimpleTextTip(Component anchorView, Component contentView) {
        super(anchorView, contentView);
    }

    /**
     * 设置文字内容
     *
     * @param text 内容
     */
    public void setTextContent(String text) {
        mContentTv.setText(text);
    }

    /**
     * 设置文字颜色
     *
     * @param value 颜色
     */
    public void setTextColorRes(int value) {
        mContentTv.setTextColor(new Color(value));
    }

    /**
     * 设置文字大小
     *
     * @param textSize 大小值
     */
    public void setTextSizeSp(int textSize) {
        mContentTv.setTextSize(textSize, Text.TextSizeType.FP);
    }

    /**
     * 设置文字对其方式
     *
     * @param gravity 对齐方式
     */
    public void setTextGravity(int gravity) {
        mContentTv.setTextAlignment(gravity);
    }

    /**
     * 设置文字与浮窗边框的间距
     *
     * @param padding 边距
     */
    public void setTextPaddingPx(int padding) {
        mContentTv.setPaddingRelative(padding, padding, padding, padding);
    }
}
